package com.mhxy.handler;

import com.mhxy.controller.TaskController;
import com.sun.jna.platform.win32.WinDef;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TaskRunHandler implements Runnable {
    private static Logger LOG = LoggerFactory.getLogger(TaskRunHandler.class);

    /**
     * 游戏窗口句柄
     */
    private WinDef.HWND hwnd_0;
    /**
     * 线程名
     */
    private String hwndName;

    public TaskRunHandler(String hwndName, WinDef.HWND hwnd_0) {
        this.hwndName = hwndName;
        this.hwnd_0 = hwnd_0;
    }

    @Override
    public void run() {
        Thread.currentThread().setName(hwndName);
        TaskProgressHandler.updateStartProgress();
        try {
            // 调度任务
            new TaskController(hwnd_0, hwndName);
        } catch (Exception e) {
            LOG.error("catch exception", e);
        } finally {
            TaskProgressHandler.updateEndProgress();
        }
    }
}
